﻿{% extends "base.html" %}

{% block title %}
Nov izpitni rok
{% endblock %}

{% block js %}

<script src="{{ MEDIA_URL }}js/search.js"></script>
<script>
	$(document).ready(function() {
	  search_setcb('professor', function (professor) {
		window.location.href = '/exams/input_exam/' + professor.pk;
	});
  
  function loadProf(selected_id){
    $("#id_executor option").remove();
    $.get('/exams/subject/executor/'+selected_id+'/', function(data) {
      if (data.length > 0){
        $("#id_executor").removeAttr('disabled');
      }
      for (i=0;i<data.length;i++){
        id = data[i].id;
        name = data[i].name;
		if(name.indexOf("{{ profi }}") != -1) {
			$("#id_executor").append("<option value=\""+id+"\">"+ name +"</option>");
		}
      }
    });        
  }
  
  if ($("#id_executor").val() == 0){
    $("#id_executor").attr("disabled","disabled");
  }else{
    loadProf($("#id_executor").val());
  }
  
  $("#id_rating_type").attr('disabled', "disabled");
  $("#id_subject").change(function(index, element){
  
    selected_id = $("#id_subject").val();  
    loadProf(selected_id);
    $.get("/exams/subject/rating_type/"+selected_id+"/", function(data){
      $("#id_rating_type").val(data.value);
    });    
  });
  
  
  $("#form_p").submit(function(){
    //hack da ga prepričam, da pošlje polje na stran.
    $("#id_rating_type").hide();
    $("#id_rating_type").removeAttr('disabled');
  
  });
  
{% if not professor %}
  search_show('professor');
{% endif %}
})
</script>

<script type="text/javascript">

 $(document).ready(function(){
    $("#id_examTime").parent().append("<div style=\"width:145px; margin-top: 15px; margin-left: 85px;\" id=\"slider-range\">&nbsp;</div>")
    $("#slider-range").slider({
        range: false,
        min: 360,
        max: 1200,
        values: [540],
        slide: slideTime,
        step: 15
    }); 
 
   $( "#id_examDate" ).datepicker();
   slideTime();
 }
);

function slideTime(event, ui){
    var minutes0 = parseInt($("#slider-range").slider("values", 0) % 60);
    var hours0 = parseInt($("#slider-range").slider("values", 0) / 60 % 24);
    $("#id_examTime").val(getTime(hours0, minutes0));
}

function getTime(hours, minutes) {
    var time = null;
    minutes = minutes + "";
    
    if (hours == 0) {
        hours = 12;
    }
    
    if (minutes.length == 1) {
        minutes = "0" + minutes;
    }
    return hours + ":" + minutes + ":00";
}

 
</script>
{% endblock %}

{% block content %}
<button onclick="search_show('professor')">Išči profesorja</button>
{% if saved and noduplicate %}
<p><b>Izpit uspešno dodan!</b></p>
{% endif %}
{% if saved and not noduplicate %}
<p><b>Izpit je že vnešen za dan predmet in danega izvajalca na izbrani dan!</b></p>
{% endif %}
<form id="form_p" action="#" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Dodaj izpitni rok" />
</form>


{% endblock %}>
